﻿using System;
using System.Collections.Generic;
using System.Text;
using KukaDataComCommon;

namespace CubeCalculations
{
   public class MovementRating : ICommands
   {
      readonly kr3_calc kr3_calc = new kr3_calc();
      public int Movements { get; set; }
      public float MovementRate { get; set; }
      public void Reset()
      {
         Movements = 0;
         MovementRate = 0f;
         kr3_calc.ResetCube(); 
         cPos = null;
      }

      #region Implementation of ICommands

      private AxisPosition cPos = null;
      public void PTP(AxisPosition end)
      {
         Movements++;
         if (cPos != null)
            MovementRate += cPos%end;
         cPos = end;
      }

      public void PTP(Position end)
      {
      }

      public void LIN(Position end)
      {
      }

      public void CIRC(Position end, Location help, float circularAngle)
      {
      }

      public void CIRC(Position end, Location help)
      {
      }

      public void GRAB(bool close)
      {
      }

      public void getCurrentPosition()
      {
      }
      public float RateSolution(Cubex Cube)
      {
         Cube.SolveCube();
         List<CubeMoves> MoveSolution = Cube.Solution();
         return RateSolution(MoveSolution);
      }

      public float RateSolution(List<CubeMoves> CubeMoves)
      {
         Reset();
         List<KR3Moves> kr3MoveSolution = kr3_calc.EvalutateSolution(CubeMoves);
         kr3_calc.ExecuteSolution(kr3MoveSolution, this);
         return MovementRate;
      }

      #endregion
   }
}
